var ns;
var app = new Vue({
    el: '#app',
    data: {
        UserName:'',
        form:{
            startMonth:9,
            ProjectID:0,
            ProjectName:'',
        },
        list: [
            { Name: '任务总数', count: 0 },
            { Name: '完成任务', count: 0 },
            { Name: '漏巡任务', count: 0 },
            { Name: '巡查任务点', count: 0 },
            { Name: '正常任务点', count: 0 },
            { Name: '漏巡任务点', count: 0 },
            { Name: '异常任务点', count: 0 },
        ],
        list2: [
            { Name: '完成率', count: '0.00%' },
            { Name: '漏检率', count: '0.00%' },
        ],
        list3: [
            { Name: '巡查记录数', count: 0 },
            { Name: '正常记录数', count: 0 },
            { Name: '异常记录数', count: 0 },
        ],//list3 临时巡查记录数量
        IsShowDate:false,
        minDate: new Date(),
        maxDate: new Date(),
        currentDate:0,
        showPopover:false,
    },
    methods: {
        formatter(type, val) {
            if (type === 'year') {
                return `${val}年`;
            }
            if (type === 'month') {
                return `${val}月`;
            }
            return val;
        },
        onOpenDate:function(){
            this.IsShowDate=true;
        },
        onCancel:function(){
            this.IsShowDate=false;
        },
        onConfirm(day) {
            var that = this;
            var y = day.getFullYear();
            var m = day.getMonth() + 1;
            var d = day.getDate();
            var h = day.getHours();
            var s = day.getMinutes();
            var nowdate = y + '-' + (m >= 10 ? m : '0' + m);
            that.IsShowDate = false;
            that.form.startMonth = nowdate;
            that.get_data();
        },
        get_data: function () {
            var that = this;  
            var options = {};
            options.action = "getusermonthreport";
            options.Month =that.form.startMonth+'-01';
            //console.log(JSON.stringify(options));
            ns.post(options, function (succeed, data, err) {
                //console.log(JSON.stringify(succeed));
                //console.log(JSON.stringify(data));
                //console.log(JSON.stringify(err));
                if (succeed) {
                    if(data.status){
                        that.list[0].count=data.total.AllTask;//任务总数
                        that.list[1].count=data.total.FinishTask;//完成任务
                        that.list[2].count=data.total.MissTask;//漏巡任务
                        that.list[3].count=data.total.AllPatrol; //巡查任务点
                        that.list[4].count=data.total.NormalPatrol;//正常任务点
                        that.list[5].count=data.total.MissPatrol; //漏巡任务点
                        that.list[6].count=data.total.AbnormalPatrol;//异常任务点
                        
                        that.list2[0].count=data.total.FinishTaskPoint;//完成率
                        that.list2[1].count=data.total.MissTaskPoint;//漏检率

                        that.list3[0].count=data.total.Total||0;//巡查记录总数
                        that.list3[1].count=data.total.Normal||0;//巡查记录总数
                        that.list3[2].count=data.total.Unusual||0;//巡查记录总数
                    }
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });

        },
        do_open_task:function(){
            var that = this;
            ns.openWin('patrolplan_tasklist', '安防巡更任务列表', {
                ProjectID: that.form.ProjectID,
                ProjectName:that.form.ProjectName,
                startMonth:that.form.startMonth,
            });
        },
        onShowPopover:function(){
            this.showPopover=!this.showPopover;
        },
        //跳转临时巡查表
        do_open_task_time:function(){
            var that = this;
            var title='临时巡查记录';
            var url='patrolplan_tasklist_record';
            ns.openWin(url, title, {
                ProjectID: that.form.ProjectID,
                ProjectName:that.form.ProjectName,
                startMonth:that.form.startMonth,
                IsAnalysis:false,
            });
        },
    }
});
apiready = function () {
    api.parseTapmode();
    ns = window.Foresight.Util;
    app.form.ID = api.pageParam.id || 0;
    //获取当前登录人姓名
    var username = api.getPrefs({
        sync: true,
        key: 'username'
    });
    app.UserName=username;
    app.minDate=new Date(moment(new Date()).add(-10, 'y'));
    app.maxDate=new Date(moment(new Date()).add(10, 'y'));
    app.currentDate=new Date();
    app.onConfirm(app.currentDate);
}
